﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using AFCEPF.BankApplication.BLL;
using AFCEPF.BankApplication.DAL;
using NUnit.Framework;

namespace AFCEPF.BankApplication.Tests
{
    [TestFixture]
    class Test_Bank
    {
        [Test]
        public void Test_SingletonUnicity()
        {
            Bank b1 = Bank.Instance;
            Bank b2 = Bank.Instance;

            Assert.AreSame(b1, b2);
        }

        [Test]
        public void Test_Property_Accounts_ForNotNull()
        {
            Bank b1 = Bank.Instance;
            Assert.NotNull(b1.Accounts);
        }

        [Test]
        public void Test_Method_GetTotalFunds()
        {
            Bank bank = Bank.Instance;

            //TODO : cacher cette méthode..
            bank.Accounts.Clear();

            for (int i = 0; i < 3; i++)
            {
                Bank.Instance.Accounts.Create(new Customer("toto" + i.ToString()), 100);
            }

            double expectedFunds = bank.GetTotalFunds();
            

            Assert.AreEqual(expectedFunds, 300);
        }

        [Test]
        public void Test_Method_GetTotalOverdrawnAmount()
        {
            Bank bank = Bank.Instance;

            //TODO : cacher cette méthode..
            bank.Accounts.Clear();

            // On crée trois comptes avec 100 €..
            for (int i = 0; i < 3; i++)
            {
                Bank.Instance.Accounts.Create(new Customer("toto" + i.ToString()), 100);
            }

            // Maintenant on retire 200 € à chacun
            // des comptes.
            foreach (var account in bank.Accounts)
            {
                account.Withdraw(200);
            }

            Assert.AreEqual(-303, bank.GetTotalOverdrawnAmount());
        }

    }
}
